<?php
include("inc.db.conf.php");
$hostid = $_GET['hostid'];

$host_query = "SELECT host FROM hosts WHERE hostid = '$hostid'";
$host_result = mysql_query($host_query, $link) or die(mysql_errno($link).mysql_error($link));
$host_row = mysql_fetch_array($host_result);
$host_name = $host_row['host'];
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <style type="text/css">
   td {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 10px;
   }
   .one {
	   background-color: #E5E5E5;
	   } 
   .two {
	   background-color: #999999;
	   text-align: left;
	   }
   tr { background: #CCCCCC; }
   tr:hover { background: #AAABFF; }
  </style>
<title>20 последних событий <? echo $host_name ?></title>
</head>
<body>

<table width="300" border="1" align="left" cellpadding="1" cellspacing="1">
    <tr width="100%">
        <td align="center" colspan="7" class="one">
        20 последних событий узла <? echo $host_name ?>
        </td>
    </tr>
    
    <tr>
        <td width="150" align="center">hostid: <b><? echo $hostid ?></b></td> 
        <td colspan="2" width="75" align="center">hostname: <b><? echo $host_name ?></b></td>

    </tr>
    
    <tr>
        <td class="two" width="150" align="center"><b>время</b></td> 
        <td width="75" align="center"><b>состояние узла</b></td>
        <td width="75" align="center"><b>прошло времени</b></td> 
    </tr>
 
<?php

$query = "
SELECT FROM_UNIXTIME(e.clock), e.value, TIMEDIFF(NOW(), FROM_UNIXTIME(e.clock)) as timedif
FROM zabbix.events e 
WHERE e.objectid IN 	(
			SELECT DISTINCT	events.objectid
			FROM triggers triggers 
				INNER JOIN events 		events ON triggers.triggerid = events.objectid
				INNER JOIN functions 	functions ON triggers.triggerid = functions.triggerid
				INNER JOIN items 		items ON functions.itemid = items.itemid
				INNER JOIN hosts 		hosts ON items.hostid = hosts.hostid
			WHERE
				hosts.hostid = '$hostid'
				AND triggers.description = 'down'
			)
ORDER BY e.clock DESC LIMIT 20";

$result=mysql_query($query, $link) or die(mysql_errno($link).mysql_error($link));

while($row = mysql_fetch_array( $result )) {
$time=$row['FROM_UNIXTIME(e.clock)'];
$timedif=$row['timedif'];
$valv=$row['value'];
	if ($valv == '0') 		{ $valv='Down';}
	elseif ($valv == '1') 	{ $valv='Up';}
	elseif ($valv == '2')	{ $valv='Unreachable';} /* ЦИКЛ НЕ ЗАКРЫТ! */
?>
<!-- Вывод -->
    <tr class="one">
        <td class="two" width="150"><?php echo $time ?></td>
        <td width="75"><? echo $valv ?></td>
        <td width="75"><? echo $timedif ?></td>
    </tr>
<!-- ВАЖНАЯ СКОБОЧКА ЗАКРЫВАЮЩАЯ ЦИКЛ! -->
<?php } ?>

    <tr width="100%">
        <td align="right" colspan="7" class="one">
        <a href="zbx-frontend.html" title="back" target="_self"><b>Назад</b></a>
        </td>
    </tr>
</table>
</body>
</html>
